<?php
/**
 * @name 配置控制器
 */
namespace app\admin\controller;
use app\common\controller\AdminBase;
class Config extends AdminBase {
    /**
     * @name 初始化
     */
    protected function _initialize(){
        //添加初始化方法
        $this->mod = model('admin/Config');
    }
    /**
     * @name 修改状态
     */
    public function saveStatus(){
        if(IS_AJAX){
            $res = false;
            $this->config_id = decrypt_id($this->config_id);
            if($this->config_id){
                $data = [
                    'config_id' => $this->config_id,
                    'status'    => $this->status
                ];
                $version = $this->version_key ?: '';
                $res = $this->mod->editConfig($data,0,$version);
            }
            if($res){
                return ['status'=>1,'data'=>['info'=>'操作成功']];
            }
        }
        return ['status'=>0,'message'=>'操作失败'];
    }
    /**
     * @name 处理删除
     */
    public function delete(){
        if(IS_POST){
           if(true !== $this->checkData(['config_id'])){
                return ['status'=>0,'message'=>$this->error_info];
            }
            $this->config_id = decrypt_id($this->config_id);
            $res = $this->mod->deleteConfig($this->config_id);
            if($res){
                return ['status' => 1,'data'=> ['info'=>'删除成功','jumpurl'=>U('admin/'.CONTROLLER_NAME.'/'.ACTION_NAME)]];
            }
        }
        return ['status' => 0,'message'=>'删除失败,未做任何删除'];
    }
}